package com.华为OD;

import java.util.Scanner;

public class t6键盘 {
    private static int board=0,screen=0;
    private static int chosen=0;
    private static void operate(int x){
        switch (x){
            case 1://输出1
                screen-=chosen;
                chosen=0;
                screen+=1;
                break;
            case 2://复制
                board=chosen;
                break;
            case 3://剪切
                board=chosen;
                screen-=chosen;
                chosen=0;
                break;
            case 4://粘贴
                screen-=chosen;
                chosen=0;
                screen+=board;
                break;
            case 5://选中所有
                chosen=screen;
                break;
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        for (int i = 0; i < s.length(); i++) {
            operate(Integer.parseInt(s.substring(i,i+1)));
        }
        System.out.println(screen);
    }
}
